package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;

import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.ui.editor.TextEditor;


public class UndoMenuItemAction extends AbstractAction {

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public UndoMenuItemAction(){

		super.putValue(Action.NAME, "Undo");
		super.putValue(Action.SHORT_DESCRIPTION, "Undo the last edition.");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		TextEditor editor = ViewContext.getMainFrame().getCurrentTextEditor();

		if(editor != null && editor.canUndo()){

			editor.undo();
		}
	}
}
